<script type="text/html" template>
    <link rel="stylesheet" href="/src/views/login/css/style.css?v={{ Math.random() }}" media="all">
</script>

<div class="loginHead">
	<img class="qp_animate01" src="/src/views/login/images/paopao.png" alt="" srcset="">
	<img class="qp_animate02" src="/src/views/login/images/paopao.png" alt="" srcset="">
	<img class="qp_animate03" src="/src/views/login/images/paopao.png" alt="" srcset="">
	<img class="qp_animate04" src="/src/views/login/images/paopao.png" alt="" srcset="">
	<img class="qp_animate05" src="/src/views/login/images/paopao.png" alt="" srcset="">
	<img class="qp_animate06" src="/src/views/login/images/paopao.png" alt="" srcset="">
	<img class="qp_animate07" src="/src/views/login/images/paopao.png" alt="" srcset="">
	<img class="qp_animate08" src="/src/views/login/images/paopao.png" alt="" srcset="">
	<img class="qp_animate09" src="/src/views/login/images/paopao.png" alt="" srcset="">
	<img class="qp_animate10" src="/src/views/login/images/paopao.png" alt="" srcset="">
</div>
<div class="loginlogo">
	<div class="sysNameLogo">
		<p>漯河市三品一特跨部门综合监管平台</p>
		<span class="">Luohe City Three Products One Special Cross Departmental Comprehensive Supervision Platform</span>
	</div>
</div>
<div class="container">
	<span></span>
	<span></span>
	<span></span>
	<form id="signinForm" class="layui-form">
		<h2>欢迎登录</h2>
		<div class="inputBox">
			<input type="text" placeholder="用户名" autocomplete="off" id="username" name="username"
				class="layui-input login-input" lay-verify="required|nickname">
		</div>
		<div class="inputBox">
			<input type="password" placeholder="密码" autocomplete="off" id="password" name="password"
				class="layui-input login-input" lay-verify="required|pass">
		</div>
		<div class="inputBox">
			<div class="input-div" id="imgCode">
				<input type="text" placeholder="验证码" autocomplete="off" id="captcha" name="captcha" maxlength="6"
					class="layui-input login-input" lay-verify="required|vercode">
				<span id="captchaDiv"></span>
			</div>
		</div>
		<!-- <div class="inputBox group">
			<a href="#">忘记密码</a>
		</div> -->
		<div class="inputBox">
			<button class="layui-btn layui-btn-normal layui-btn-fluid login-btn" lay-filter="login"
				lay-submit>立即登录</button>
		</div>
	</form>
</div>
<div class="loginbottom"></div>

<script src="/layui/layui.js"></script>
<script>
	layui.config({
		base: '/src/'
	}).use(['index', 'jm'], function () {

		var $ = layui.$,
			setter = layui.setter,
			admin = parent.layui.admin,
			form = layui.form,
			jm = layui.jm,
			captchaId = 'yongjie_captcha_Id',
			HostVerifyCode = function () {
				admin.req({
					url: 'sysAuth/getCaptcha',
					type: 'get',
					done: function (res) {
						layui.sessionData(setter.tableName, {
							key: captchaId,
							expiredtime:res.data.expiredtime,
							value: res.data.id
						});
						$("#captchaDiv").html('<img src="data:image/png;base64,' + res.data.img + '"  alt="验证码" />');
					}
				});
			};


		form.verify({
			nickname: function (value) {
				if (value.length < 1) {
					return '用户名长度不少于1个字符';
				}
				if (!new RegExp("^[-a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)) {
					return '用户名不能有特殊字符';
				}
				if (/(^\_)|(\__)|(\_+$)/.test(value)) {
					return '用户名首尾不能出现下划线\'_\'';
				}
			},
			pass: function (value) {
				if (!new RegExp(/^(?=.*?[a-z])(?=.*?[A-Z])(?=.*?\d)(?=.*?[!#@*&.])[a-zA-Z\d!#@*&.]*$/).test(value)) {
					return '用户密码必须包含大写字母、小写字母、数字、特殊符号！';
				}
			},
			vercode: function (value) {
				if (!new RegExp(/^\d+$/).test(value)) {
					return '输入合法验证码！';
				}
			}
		});

		//初始化验证码
		HostVerifyCode();

		//验证码切换
		$("#captchaDiv").on('click', function () {
			HostVerifyCode();
		});

		// 进行登录操作
		form.on('submit(login)', function (obj) {
			var reg1 = /^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$/;
			if (reg1.test(obj.field.password)) {
				var that = $(this);
				that.text("登录中...").attr("disabled", "disabled").addClass("layui-disabled");
				var username = jm.s4.encryptData_ECB(obj.field.username);
				var password = jm.s4.encryptData_ECB(obj.field.password);
				var code=obj.field.captcha;
				admin.req({
					url: 'sysAuth/login',
					type: 'post',
					data: JSON.stringify({
						account: username,
						password: password,
						codeid: layui.sessionData(setter.tableName)[captchaId],
						code: code
					}),
					contentType: 'application/json',
					done: function (res) {
						if (res.successful) {							
							layer.msg('登录成功！', {
								offset: '15px',
								icon: 1,
								time: 1000
							}, function () {
								layui.sessionData(setter.tableName, {
									key: setter.request.tokenName,
									value: res.data.accesstoken
								});
								layui.sessionData(setter.tableName, {
									key: setter.request.RefreshToken,
									value: res.data.refreshtoken
								});
								layui.sessionData(setter.tableName, {
									key: 'ExpiredTime',
									value: res.data.expiredtime
								});
								layui.sessionData(setter.tableName, {
									key: 'TimeSpan',
									value: Date.now()
								});
								layui.sessionData(setter.tableName, {
									key: 'UserScreenValue',
									value: password
								});
								location.href = '/';
							});
						} else {
							that.text("立即登录").removeAttr("disabled").removeClass("layui-disabled");
							// layer.msg(res.msg, {
							// 	time: 2000
							// });
							layui.main.msg_error(res.msg);
							HostVerifyCode();
						}
					}
				});
				return false;
			} else {
				layer.msg("密码长度8位以上（包含8位），至少1个大写字母，1个小写字母，1个数字和一个特殊字符！");
				return false;
			}
			return false;
		});

	})
</script>